package br.com.hotel.dao;

import java.util.ArrayList; 
import java.util.Date;
import java.util.List;

import org.hibernate.annotations.NamedQuery;

import br.com.hotel.entity.Preco;
import br.com.hotel.entity.Produto;

public class PrecoDAO extends GenericJpaRepository<Preco, Long>{

	public List<Preco> diaria;
	public PrecoDAO() throws ClassNotFoundException{
		createEntityManager();
	}
	
	public List<Preco> getPrecos(){
		
		return findAll();
	}
	public Preco getPreco(Long produto_id){
		javax.persistence.Query query = getEntityManager().createNamedQuery("Preco.findAll");
		query.setParameter(1, produto_id).setParameter(2, new Date()).setParameter(3,new Date());
		return (Preco)query.getSingleResult();
	}
	
	public Boolean hasPreco(Long serviceId,Long tabId){
		javax.persistence.Query query = getEntityManager().createQuery("SELECT p FROM Preco p WHERE p.service.Id = "+serviceId +
				" AND p.tabelaPreco.Id = "+tabId);
		if(query.getResultList().size()==0)
			return false;
		return true;
	}
	
	
	
}